package com.xk.pojo;

import java.util.List;

public class Page<T> {
    // 当前页码
    private int currentPage;
    // 每页显示的记录数
    private int pageSize;
    // 总记录数
    private long totalRecords;
    // 总页数
    private int totalPages;
    // 当前页的数据列表
    private List<T> dataList;

    // 构造方法
    public Page() {
    }

    public Page(int currentPage, int pageSize, long totalRecords) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalRecords = totalRecords;
        // 计算总页数
        this.totalPages = (int) Math.ceil((double) totalRecords / pageSize);
    }
    // 获取当前页的起始索引
    public int getStartIndex() {
        return (currentPage - 1) * pageSize;
    }

    // 获取当前页的结束索引
    public int getEndIndex() {
        return Math.min(getStartIndex() + pageSize, (int) totalRecords);
    }

    // 省略其他可能需要的方法，比如添加数据到dataList等

    // getter和setter方法
    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public long getTotalRecords() {
        return totalRecords;
    }

    public void setTotalRecords(long totalRecords) {
        this.totalRecords = totalRecords;
        // 更新总页数
        this.totalPages = (int) Math.ceil((double) totalRecords / pageSize);
    }

    public int getTotalPages() {
        return totalPages;
    }

    public void setTotalPages(int totalPages) {
        this.totalPages = totalPages;
    }

    public List<T> getDataList() {
        return dataList;
    }

    public void setDataList(List<T> dataList) {
        this.dataList = dataList;
    }
}
